package cn.netswap.jeegorilla.framework.security.config;

import cn.netswap.jeegorilla.framework.security.filter.ImageValidCodeFilter;
import cn.netswap.jeegorilla.framework.security.handler.GorillaAuthenticationFailureHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.stereotype.Component;

/**
 * @author lgw
 * @version 1.0
 * @date 2020/3/20 17:20
 */
@Component
public class InvidCodeAuthenticationSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    @Autowired
    private GorillaAuthenticationFailureHandler gorillaAuthenticationFailureHandler;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        ImageValidCodeFilter imageValidCodeFilter = new ImageValidCodeFilter();
        imageValidCodeFilter.setGorillaAuthenticationFailureHandler(gorillaAuthenticationFailureHandler);
        http.addFilterBefore(imageValidCodeFilter, UsernamePasswordAuthenticationFilter.class);
    }
}
